package com.dfbz.demo03_lanbda表达式练习;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo01 {


    public static void main(String[] args) {
        method3((str) -> {
            System.out.println("您输入的值为: " + str);
            return str.length() == 3 ? true : false;
        });
    }

    public static void method3(TestLambda3 t) {
        Boolean flag = t.run("hello");
        System.out.println(flag);
    }


    public static void param2(String[] args) {
//        Xxx xxx = new Xxx();


        /*TestLambda2 xxx = new TestLambda2() {
            @Override
            public void run(String str) {
                System.out.println("您输入的值为: " + str);
            }
        };*/

        TestLambda2 xxx = (str) -> System.out.println("您输入的值为: " + str);
        method2(xxx);
    }

    public static void method2(TestLambda2 t) {
        t.run("hello");
    }


    public static void param1(String[] args) {

        /*
        class Xxx implements TestLambda1{
            public void run(){
                System.out.println("hello")
            }
        }
         TestLambda1 t1 =new Xxx();
         */

        TestLambda1 t1 = () -> System.out.println("hello");

        method1(() -> System.out.println("hello"));
    }

    public static void method1(TestLambda1 t1) {
        t1.run();
    }

    public static void test3(String[] args) {

        /*TestLambda3 t1 = new TestLambda3() {
            @Override
            public Boolean run(String str) {
                System.out.println("您输入的值为: " + str);
                return str.length() > 3 ? true : false;
            }
        };

        Boolean flag = t1.run("hello");
        System.out.println(flag);*/

        TestLambda3 t2 = (str) -> {
            System.out.println("您输入的值为: " + str);
            return str.length() == 3 ? true : false;
        };

        Boolean flag = t2.run("aaa");
        System.out.println(flag);
    }

    public static void test2(String[] args) {

        TestLambda2 t1 = new TestLambda2() {
            @Override
            public void run(String str) {
                System.out.println("你输入的值为: " + str);
            }
        };
//        t1.run("hello");


        TestLambda2 t2 = (str) -> System.out.println("您输入的值为: " + str);
        t2.run("hello world");

    }

    public static void test(String[] args) {


        TestLambda1 t2 = new TestLambda1() {
            @Override
            public void run() {
                System.out.println("aaa");
            }
        };

        TestLambda1 t1 = () -> System.out.println("bbb");
        t1.run();

    }

}

class Xxx implements TestLambda2 {
    @Override
    public void run(String str) {
        System.out.println("您输入的值为: " + str);
    }
}

interface TestLambda3 {
    Boolean run(String str);
}

interface TestLambda2 {
    void run(String str);
}

interface TestLambda1 {
    void run();
}


